﻿@model IEnumerable<ESupervision.Models.MessageRecipient>

@{
    ViewBag.Title = "Messaging - Inbox";
}


<h2>Messaging - Inbox</h2>


<div class="row">
    <div class="col-md-2">
        <p>
            <button type="button" class="btn btn-warning" onclick="location.href='@Url.Action("Compose")'">Compose</button>

        </p>
        <ul class="nav nav-pills nav-stacked">
            <li role="presentation" class="active"><a href="#">Inbox</a></li>
            <li role="presentation"><a href="@Url.Action("Sent")">Sent</a></li>
        </ul>

    </div>
    @using (Html.BeginForm("DoAction", "Message")) 
    {
         @Html.AntiForgeryToken()
    <div class="col-md-10">
        <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Actions <span class="caret"></span></button>
            <ul class="dropdown-menu" role="menu">
                <li><button type="submit" name="command" value="Delete" class="btn btn-link">Delete</button></li>
                <li><button type="submit" name="command" value="Mark As Read" class="btn btn-link">Mark As Read</button></li>
                <li><button type="submit" name="command" value="Mark As UnRead" class="btn btn-link">Mark As UnRead</button></li>
            </ul>
        </div>
        <div>
            <hr/>
        </div>
        <table class="table">
            <tr>
                <th><input type="checkbox" id="selectAll" name="selectAll" /></th>
                <th>From</th>
                <th>Subject</th>
                <th>Time</th>
            </tr>

            @foreach (var item in Model)
            {
                if (item.MessageStatus == ESupervision.Models.MessageStatus.Unread)
                { 
                    <tr>
                        <td>
                            <input type="checkbox" name="selectedMessages" value="@item.MessageRecipientID" />
                        </td>
                        <td>
                            <b>@Html.DisplayFor(modelItem => item.Message.Sender.FullName)</b>
                        </td>
                        <td>
                            <b>@Html.ActionLink(item.Message.Subject, "Read", new { id = item.MessageID, rId = item.MessageRecipientID })</b>
                        </td>
                        <td>
                             <b>@Html.DisplayFor(modelItem => item.ReceivedTime)</b>
                        </td>
                    </tr>
                }
                else
                {
                    <tr>
                        <td>
                            <input type="checkbox" name="selectedMessages" value="@item.MessageRecipientID" />
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Message.Sender.FullName)
                        </td>
                        <td>
                            @Html.ActionLink(item.Message.Subject, "Read", new { id = item.MessageID, rId = item.MessageRecipientID })
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.ReceivedTime)
                        </td>
                    </tr>
                
                }
            }

        </table>
    </div>
    }
</div>
@section scripts {
    <script>
        $('#selectAll').change(function () {
            if ($(this).prop('checked')) {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', true);
                });
            } else {
                $('tbody tr td input[type="checkbox"]').each(function () {
                    $(this).prop('checked', false);
                });
            }
        });
    </script>
}